API Documentation
Public Member Functions | Public Attributes | List of all members
nkMaths::Quaternion Class Reference

A quaternion, symbolizing rotations as a 4D vector. More...

Public Member Functions

 Quaternion ()
 
 Quaternion (float x, float y, float z, float w)
 
 Quaternion (const Vector &axis, float angle)
 
 Quaternion (const Vector &eulerAngles)
 
 Quaternion (const Matrix &mat)
 
 Quaternion (const Quaternion &other)
 
 ~Quaternion ()
 
Vector getAsEulerAngles () const
 
Quaternion & setFromAxisAngle (const Vector &axis, float angle)
 
Quaternion & setFromEuler (const Vector &angles)
 
Quaternion & setFromOrientationMatrix (const Matrix &mat)
 
Quaternion & setFromTransformationMatrix (const Matrix &mat)
 
Vector transform (const Vector &vector) const
 
Vector & apply (Vector &vector) const
 
void fromString (const nkMemory::StringView &str)
 
Quaternion & operator= (const Quaternion &other)
 
Vector operator* (const Vector &other) const
 
Quaternion operator* (const Quaternion &other) const
 
void operator*= (const Quaternion &other)
 
bool operator== (const Quaternion &other) const
 

Public Attributes

float _x
 X component of the quaternion.
 
float _y
 Y component of the quaternion.
 
float _z
 Z component of the quaternion.
 
float _w
 W component of the quaternion.
 

Detailed Description

A quaternion, symbolizing rotations as a 4D vector.

The equation for the quaternion is considered as : xi + yj + zk + w.

Constructor & Destructor Documentation

◆ Quaternion() [1/6]

nkMaths::Quaternion::Quaternion ( )

Default constructor. Defaults to (0, 0, 0, 1), encoding no rotation.

◆ Quaternion() [2/6]

nkMaths::Quaternion::Quaternion ( float  x,
float  y,
float  z,
float  w 
)

Filling constructor.

Parameters
xThe x component.
yThe y component.
zThe z component.
wThe w component.

◆ Quaternion() [3/6]

nkMaths::Quaternion::Quaternion ( const Vector &  axis,
float  angle 
)

Axis angle constructor.

Parameters
axisThe axis of rotation to consider.
angleThe angle around this axis, in radians.

◆ Quaternion() [4/6]

nkMaths::Quaternion::Quaternion ( const Vector &  eulerAngles)

Euler angles constructor.

Parameters
eulerAnglesThe euler angles, considering rotation in ZYX (Yaw-Pitch-Roll) order.

◆ Quaternion() [5/6]

nkMaths::Quaternion::Quaternion ( const Matrix &  mat)

Matrix constructor.

Parameters
matThe matrix from which to extract the rotation.

◆ Quaternion() [6/6]

nkMaths::Quaternion::Quaternion ( const Quaternion &  other)

Copy constructor.

Parameters
otherThe quaternion to copy.

◆ ~Quaternion()

nkMaths::Quaternion::~Quaternion ( )

Destructor.

Member Function Documentation

◆ getAsEulerAngles()

Vector nkMaths::Quaternion::getAsEulerAngles ( ) const
Returns
The quaternion translated as euler angles, encoded with ZYX ordering (Yaw-Pitch-Roll).

◆ setFromAxisAngle()

Quaternion& nkMaths::Quaternion::setFromAxisAngle ( const Vector &  axis,
float  angle 
)

Sets the quaternion from an axis and angle pair.

Parameters
axisThe axis to rotate around.
angleThe angle to rotate, in radians.
Returns
Reference over caller.

◆ setFromEuler()

Quaternion& nkMaths::Quaternion::setFromEuler ( const Vector &  angles)

Sets the quaternion from euler angles.

Parameters
anglesThe euler angles to translate, considering rotation in ZYX (Yaw-Pitch-Roll) order.
Returns
Reference over caller.

◆ setFromOrientationMatrix()

Quaternion& nkMaths::Quaternion::setFromOrientationMatrix ( const Matrix &  mat)

Sets the quaternion from a rotation matrix.

Parameters
matThe matrix to extract the rotation from.
Returns
Reference over caller.

◆ setFromTransformationMatrix()

Quaternion& nkMaths::Quaternion::setFromTransformationMatrix ( const Matrix &  mat)

Sets the quaternion from a full transformation matrix.

Parameters
matThe matrix to extract the rotation from.
Returns
Reference over caller.

◆ transform()

Vector nkMaths::Quaternion::transform ( const Vector &  vector) const

Rotates a vector, by copying it and returning it. Another way to express q * v.

Parameters
vectorThe vector to rotate.
Returns
The vector once rotated.

◆ apply()

Vector& nkMaths::Quaternion::apply ( Vector &  vector) const

Rotates a vector, by altering the vector parameter. Another way to express q *= v.

Parameters
vectorThe vector to rotate.
Returns
The vector given, once rotated.

◆ fromString()

void nkMaths::Quaternion::fromString ( const nkMemory::StringView &  str)

Parse components from a string. Format is "x,y,z,w".

Parameters
strThe string to parse.

◆ operator=()

Quaternion& nkMaths::Quaternion::operator= ( const Quaternion &  other)

Assignment operator.

Parameters
otherThe quaternion to assign.

◆ operator*() [1/2]

Vector nkMaths::Quaternion::operator* ( const Vector &  other) const

Multiplication operator.

Parameters
otherThe vector to apply the quaternion to.
Returns
The vector, rotated by the quaternion.

◆ operator*() [2/2]

Quaternion nkMaths::Quaternion::operator* ( const Quaternion &  other) const

Multiplication operator.

Parameters
otherThe quaternion to multiply with.
Returns
A quaternion being the result of the multiplication of both quaternions.

◆ operator*=()

void nkMaths::Quaternion::operator*= ( const Quaternion &  other)

Multiplication and assignment operator.

Parameters
otherThe quaternion to multiply with.

◆ operator==()

bool nkMaths::Quaternion::operator== ( const Quaternion &  other) const

Comparison operator.

Parameters
otherThe quaternion to compare with.
Returns
Whether the quaternions have the same component values (true) or not (false).

The documentation for this class was generated from the following file: